package es.uclm.itsue.interfaces;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.widget.EditText;

public class EditTextActivity extends Activity implements OnKeyListener {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.edittext_layout);
        
        EditText et1 = (EditText) findViewById(R.id.editText1);
        et1.setOnKeyListener(this);
/*
        et1.setOnKeyListener(new View.OnKeyListener() {

        	@Override
			public boolean onKey(View v, int keyCode, KeyEvent event) {

        		if (event.getAction() != KeyEvent.ACTION_DOWN) return false;

        		Log.i(getPackageName(), "Pulsada una tecla");
        		if (keyCode != KeyEvent.KEYCODE_ENTER) return false;
				
        		Log.i(getPackageName(), "Aceptamos cambios.");
				EditText et1 = (EditText) findViewById(R.id.editText1);
				EditText et2 = (EditText) findViewById(R.id.editText2);
				et2.setText(et1.getText());
		        return true;
			}
		});
*/
    }

	@Override
	public boolean onKey(View v, int keyCode, KeyEvent event) {

		switch (v.getId()) {

		case R.id.editText1:
			if (event.getAction() != KeyEvent.ACTION_DOWN) return false;

			Log.i(getPackageName(), "Pulsada una tecla");
			if (keyCode != KeyEvent.KEYCODE_ENTER) return false;
			
			Log.i(getPackageName(), "Aceptamos cambios.");
			EditText et1 = (EditText) findViewById(R.id.editText1);
			EditText et2 = (EditText) findViewById(R.id.editText2);
			et2.setText(et1.getText());
	        return true;
	        
		default:
			return false;
		}
	}
}
	
	